package net.test;

// 导入 Apache HttpClient 的类
import org.apache.http.Header;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.util.EntityUtils;

public class test10_httpclient {
    public static void main(String[] args) {
        // 目标网址，这里以京东官网为例
        String url = "http://www.hyycinfo.com/Examination2.0/login.html";

        // 使用 try-with-resources 语句确保资源的正确关闭
        try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
            // 创建一个 GET 请求
            HttpGet httpGet = new HttpGet(url);

            // 执行请求并获取响应
            try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
                // 将响应内容转换为字符串
                String responseBody = EntityUtils.toString(response.getEntity());

                // 打印响应体的内容
                System.out.println("Response body: " + responseBody);
            }
        } catch (Exception e) {
            // 捕获并打印异常信息
            e.printStackTrace();
        }

    }
}
